package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.IncomeManage;
import cn.wolfcode.crm.domain.IncomeManage;
import cn.wolfcode.crm.domain.OutcomeManage;
import cn.wolfcode.crm.mapper.IncomeManageMapper;
import cn.wolfcode.crm.query.IncomeManageQueryObject;
import cn.wolfcode.crm.service.IIncomeManageService;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class IncomeManageServiceImpl implements IIncomeManageService {
    @Autowired
    private IncomeManageMapper incomeManageMapper;


    @Override
    public IncomeManage selectByPrimaryKey(Long id) {
        return incomeManageMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<IncomeManage> selectAll() {
        return incomeManageMapper.selectAll();
    }


    //改变审核状态和查询审核人
    @Override
    public void changState(Long id) {
        Long auditorId = null;
        IncomeManage incomeManage = incomeManageMapper.selectByPrimaryKey(id);
        if (incomeManage.getState() ==null || !incomeManage.getState()){

            Employee auditor = (Employee) SecurityUtils.getSubject().getPrincipal();
            auditorId = auditor.getId();
        }
        incomeManageMapper.changState(auditorId,id);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        incomeManageMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(IncomeManage entity) {
        incomeManageMapper.insert(entity);
    }

    @Override
    public void updateByPrimaryKey(IncomeManage entity) {
        incomeManageMapper.updateByPrimaryKey(entity);
    }

    @Override
    public PageResult query4List(IncomeManageQueryObject qo) {
        Integer total = incomeManageMapper.query4Count(qo);
        if (total == 0) {
            return PageResult.PAGERESULT_EMPTY;
        }
        return new PageResult(total, incomeManageMapper.query4List(qo));
    }
}
